﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Newtonsoft.Json;

public partial class Dp : Basic
{
    public string code = "000001";
    public string strZlyj = "";  //主力研究
    public string strScxw = "";  //市场新闻
    public string strLzbk = "";  //领涨板块
    public string strZlzj = "";  //主力资金流入
    public string strPool = "";  //股票池
    public string strZshq = "";  //指数行情
    public string strGszj = "";  //股市直击
    public string strCW = "";  //仓位表
    public string strCPZY = "";
    public int cTime = 10;  //当前几点钟

    protected void Page_Load(object sender, EventArgs e)
    {
        code = OTO.ToStr(Request["code"], "000001");
        cTime = DateTime.Now.Hour;
        if (OTO.IsSCode(code) == false)
        {
            Response.Write("<script>alert(\"请不要进行非法操作！\");this.location.href='/';</script>");
            Response.End();
        }

        _title = "指数(" + code + ")-股票行情中心-益盟操盘手";
        _keywords = "个股，行情,大盘,指数,权证,基金,综合排行,自选股,高速行情,益盟操盘手,操盘手软件,益盟官网-益盟操盘手";
        _desc = "益盟操盘手行情中心提供及时而准确的个股行情、以及大盘指数，涵盖个股行情、板块行情、大盘指数、权证、基金、综合排行、自选股、高速行情、个股档案、论坛等内容。";

        strZlyj = sb主力研究("0105").ToString();

        strScxw = sb主力研究("0303").ToString();

        strLzbk = sb领涨板块().ToString();

        strZlzj = sb主力资金流入().ToString();

        strPool = sb股票池().ToString();

        strZshq = sb指数行情().ToString();

        strGszj = sb股市直击().ToString();

        strCW = sb仓位表().ToString();

        strCPZY = str操盘摘要(code).ToString();

        BasicHeader(_title, string.Empty, string.Empty, _desc, _keywords);
    }

    protected StringBuilder sb主力研究(string typeid)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            NewsByTypeEnty obj = JsonConvert.DeserializeObject<NewsByTypeEnty>(Pub.LoadData(jsonUrl + "news/NewsList.ashx?typeid=" + typeid + "&top=10"));
            if (obj != null)
            {
                List<NewsEnty> list = obj.list;
                sb.AppendLine("<ul>");
                int len = 9;
                if (list.Count < len)
                    len = list.Count;
                for (int i = 0; i < len; i++)
                {
                    sb.AppendFormat(" <li>·<a href=\"{0}\" target=\"_blank\">{1}</a></li>", GetNewsUrl("11", typeid, list[i].Id), list[i].Title);
                }
                sb.AppendLine("</ul>");
            }
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb领涨板块()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            List<BkPhEnty> list = JsonConvert.DeserializeObject<List<BkPhEnty>>(Pub.LoadData(jsonUrl + "hangqing/lzbk.ashx"));

            sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
            sb.AppendLine("  <tr class=\"tableSmall1Head\">");
            sb.AppendLine("    <td class=\"gray\">板块名称</td>");
            sb.AppendLine("    <td class=\"gray\">涨跌幅</td>");
            sb.AppendLine("    <td class=\"gray\" width=\"58\" align=\"center\">操盘线</td>");
            sb.AppendLine("  </tr>");
            int i = 0;
            list = list.Take(10).ToList();
            foreach (var m in list)
            {
                i++;
                string _class = " class=\"bgGray\"";
                if (i % 2 == 0)
                    _class = "";
                sb.AppendFormat("  <tr {0}>", _class);
                sb.AppendFormat("    <td><a href=\"Bk{1}.shtml\" class=\"b\">{0}</a></td>", m.N, m.C);
                sb.AppendFormat("    <td class=\"red\">{0}</td>", OTO.PerRedGre(m.F, 1, 2, "-", "%"));
                sb.AppendFormat("    <td class=\"{1}\" align=\"center\" title=\"{2}\">{0}</td>", Math.Abs(m.NC), m.NC < 0 ? "bg_tipG" : "bg_tipR", Pub.NcTip(m.NC));
                sb.AppendLine("  </tr>");
            }
            sb.AppendLine("</table>");
        }
        catch
        {
            sb = new StringBuilder();
        }
        return sb;
    }

    protected StringBuilder sb股票池()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string str = Pub.LoadData(jsonUrl + "hangqing/Hero_Pool.ashx").Replace("\\\"", "\"").Replace("\"[", "[").Replace("]\"", "]");
            var obj = JsonConvert.DeserializeObject<StockPoolEnty>(str);
            if (obj != null)
            {
                List<SPItEnty> r = obj.red;
                List<SPItEnty> b = obj.blue;

                List<SPItEnty> list = obj.blue;
                if (r.Count > 0)
                    list = obj.red;

                int len = 4;
                if (list.Count < len)
                    len = list.Count;
                sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
                sb.AppendLine("<tr class=\"tableSmallHead\">");
                sb.AppendLine("  <td class=\"gray\">股票名称</td>");
                sb.AppendLine("  <td class=\"gray\">入选时间</td>");
                sb.AppendLine("  <td class=\"gray\">入选价格</td>");
                sb.AppendLine("  <td class=\"gray\">阶段涨幅</td>");
                sb.AppendLine("</tr>");
                for (int i = 0; i < len; i++)
                {
                    sb.AppendLine("<tr class=\"bgGray\">");
                    sb.AppendFormat("      <td><a href=\"Gg{1}.shtml\" class=\"b\">{0}</a></td>", list[i].N, list[i].C);
                    sb.AppendFormat("      <td>{0}</td>", OTO.ToDate(list[i].DATE, "-"));
                    sb.AppendFormat("      <td>{0}</td>", list[i].P);
                    sb.AppendFormat("      <td>{0}</td>", OTO.PerRedGre(list[i].F, 1, 2, "-", "%"));
                    sb.AppendLine("</tr>");
                }
                sb.AppendLine("</table>");
            }
        }
        catch
        { }
        return sb;
    }

    protected StringBuilder sb主力资金流入()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            List<BkPhEnty> list = JsonConvert.DeserializeObject<List<BkPhEnty>>(Pub.LoadData(jsonUrl + "hangqing/zlzjlrbk.ashx"));

            sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
            sb.AppendLine("  <tr class=\"tableSmall1Head\">");
            sb.AppendLine("    <td class=\"gray\">板块名称</td>");
            sb.AppendLine("    <td class=\"gray\">涨跌幅</td>");
            sb.AppendLine("    <td class=\"gray\" width=\"58\" align=\"center\">操盘线</td>");
            sb.AppendLine("  </tr>");
            int i = 0;
            list = list.Take(10).ToList();
            foreach (var m in list)
            {
                i++;
                string _class = " class=\"bgGray\"";
                if (i % 2 == 0)
                    _class = "";
                sb.AppendFormat("  <tr {0}>", _class);
                sb.AppendFormat("    <td><a href=\"Bk{1}.shtml\" class=\"b\">{0}</a></td>", m.N, m.C);
                sb.AppendFormat("    <td class=\"red\">{0}</td>", OTO.PerRedGre(m.F, 1, 2, "-", "%"));
                sb.AppendFormat("    <td class=\"{1}\" align=\"center\" title=\"{2}\">{0}</td>", Math.Abs(m.NC), m.NC < 0 ? "bg_tipG" : "bg_tipR", Pub.NcTip(m.NC));
                sb.AppendLine("  </tr>");
            }
            sb.AppendLine("</table>");
        }
        catch
        {
            sb = new StringBuilder();
        }
        return sb;
    }

    protected StringBuilder sb指数行情()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            List<ZshqEnty> list = JsonConvert.DeserializeObject<List<ZshqEnty>>(Pub.LoadData(jsonUrl + "hangqing/hyzyzslb.ashx"));
            sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
            sb.AppendLine("  <tr class=\"tableSmall1Head gray\">");
            sb.AppendLine("	<td>A股市场</td>");
            sb.AppendLine("	<td>最新</td>");
            sb.AppendLine("	<td>涨跌幅</td>");
            sb.AppendLine("	<td>主力净买</td>");
            sb.AppendLine("	<td>股票数量</td>");
            sb.AppendLine("	<td>涨跌家数</td>");
            sb.AppendLine("	<td width=\"58\" align=\"center\">操盘线</td>");
            sb.AppendLine("  </tr>");
            for (int i = 0; i < list.Count; i++)
            {
                string _class = "";
                if (i % 2 == 0)
                    _class = " class=\"bgGray\"";
                sb.AppendFormat("  <tr {0}>", _class);
                sb.AppendFormat("	<td><a href=\"Dp{1}.shtml\">{0}</a></td>", list[i].scmc, list[i].code);
                sb.AppendFormat("	<td><span class=\"green\">{0}</span></td>", OTO.PerRedGre(list[i].P, list[i].F, 1, 2, "-", ""));
                sb.AppendFormat("	<td>{0}</td>", OTO.PerRedGre(list[i].F, 2, "-", "%"));
                sb.AppendFormat("	<td>{0}</td>", OTO.PerRedGre(list[i].J, 100000000, 2, "-", ""));
                sb.AppendFormat("	<td>{0}</td>", list[i].gpCount);
                sb.AppendFormat("	<td>{0}/{1}</td>", list[i].uCount, list[i].dCount);
                sb.AppendFormat("	<td class=\"{1}\" align=\"center\" title=\"{2}\">{0}</td>", Math.Abs(list[i].NC), list[i].NC > 0 ? "bg_tipR" : "bg_tipG", Pub.NcTip(list[i].NC));
                sb.AppendLine("  </tr>");
            }
            sb.AppendLine("</table>");
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb股市直击()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string str = Pub.LoadData(jsonUrl + "news/NewsListMany.ashx?typeid=0303&top=8");
            List<NewsList> list = JsonConvert.DeserializeObject<List<NewsList>>(str);
            if (list != null && list[0].list.Length > 0)
            {
                sb.AppendFormat("<ul>");
                foreach (var m in list[0].list)
                {
                    sb.AppendFormat("<li><span class=\"gray\">{0}</span> <a href=\"{2}\">{1}</a></li>", OTO.ToDate(m.PTime, DateTime.Now).ToString("HH:mm"), m.Title, GetNewsUrl("11", "0303", m.Id));
                }
                sb.AppendFormat("</ul>");
            }
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb仓位表()
    {
        StringBuilder sb = new StringBuilder();
        string str = Pub.LoadData(jsonUrl + "comm/weather.ashx");
        WeatherEnty obj = JsonConvert.DeserializeObject<WeatherEnty>(str);
        if (obj != null)
        {
            sb.AppendFormat("<span class=\"font-weight\">建议仓位：</span><span class=\"font30 font-weight red\" id=\"posi\">{0}</span><span class=\"font35 font-weight red\">%</span>", OTO.ToDecimal(obj.posi, 0));
            sb.AppendFormat("<br /><span class=\"font-weight\">中期操作：</span>{0}", obj.short_strategy);
            sb.AppendFormat("<br /><span class=\"font-weight\">短期操作：</span>{0}", "");
        }
        return sb;
    }

    protected string str操盘摘要(string code)
    {
        string rel = "";
        try
        {
            rel = Pub.LoadData(jsonUrl + "hangqing/cpzy.ashx?code=" + code);
        }
        catch {
            rel = "";
        }
        return rel;
    }

}